package com.guangyunl.b_method;

import java.util.Scanner;

//需求:
//求出1~100的和，并将结果返回
public class Demo02Method {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("请输入开始的整数:");
        int start1 = sc.nextInt();
        System.out.println();

        System.out.print("请输入结束的整数:");
        int end1 = sc.nextInt();
        System.out.println();

        int result = sum(start1, end1);
        System.out.println("从" + start1 + "加到" + end1 +" 的和 = " + result);
    }

    public static int sum(int a, int b){
        int sum = 0;
        for (int i = a; i <= b ; i++) {
            sum = i + sum ;
        }
        return sum;
    }
}
/*
请输入开始的整数:1

请输入结束的整数:100

从1加到100 的和 = 5050
 */